from http.server import SimpleHTTPRequestHandler, HTTPServer
import urllib
from urllib.parse import urlencode,urlparse, parse_qs, unquote
import os, string, sys, time, re, math, fileinput, glob, shutil
from string import Template
import chardet
import json
from aiohttp import web
from model.FileInf import FileInf
from datetime import datetime,timedelta
from PathBuilder import PathBuilder
import uuid
import SqlFile
from mmap import mmap, ACCESS_WRITE 
import base64
from FileBlockWriter import FileBlockWriter
from io import BytesIO

class FormReader:
    fields={}
    buffer=BytesIO()

    async def read(self,request):
        parts = await request.multipart()
        async for field in parts:
            if field.name == "file":
                while True:
                    chunk = await field.read_chunk()
                    if not chunk:
                        break
                    self.buffer.write(chunk)
                self.buffer.seek(0)
            else:
                self.fields[field.name] = await field.read(decode=True)